/*
 * vim: ts=4 sw=4 fdm=marker noet tw=78 ai
 * %%LICENSE%%
 */
#include <sys/cdefs.h>
#ifdef __FBSDID
__FBSDID("$Coar$");
#endif

#include <assert.h>
#include <err.h>

#include <ldap.h>

#include "extern.h"
#include "search.h"

int
lde_search_entry(runtime_t *ctx, LDAPMessage **result)
{
	int res;

	TRACEIN(ctx, __func__, "filter=%s", ctx->arg_entry);
	*result = NULL;

	res = ldap_search_ext_s(ctx->ld, ctx->opt_base, ctx->opt_scope,
			ctx->arg_entry, NULL, 0, NULL, NULL, NULL, -1, result);

	TRACEOUT(ctx, __func__, "returning %i", res);
	return (res);
}

int
lde_search_operational(runtime_t *ctx, char *type, LDAPMessage **result)
{
	char *attrs[2] = { type, NULL };
	int res;

	assert(ctx != NULL);
	assert(ctx->ld != NULL);
	assert(type != NULL);
	TRACEIN(ctx, __func__, "sending operational query for %s", type);
	*result = NULL;
	res = ldap_search_ext_s(ctx->ld, "cn=subschema", LDAP_SCOPE_BASE,
			NULL, attrs, 0, NULL, NULL, NULL, -1, result);
	TRACEOUT(ctx, __func__, "Returning 0x%02x and result %p", res, *result);
	return (res);
}
